package com.shop.system.controller;

import com.shop.common.core.domain.Result;
import com.shop.system.domain.User;
import com.shop.system.service.UserService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/findByName")
    public Result<User> findByName(@RequestParam String userName){
        User byName = userService.findByName(userName);
        return Result.success(byName);
    }

    @GetMapping("/show")
    public List<User> show(){
        return userService.show();
    }

    @PostMapping("/insert")
    public Result<User> insert(@RequestBody User user){
        return userService.insert(user);
    }

    @PostMapping("/upd")
    public Result<User> upd(@RequestBody User user){
        return userService.upd(user);
    }

    @GetMapping("/del")
    public Result<User> del(@RequestParam Integer id){
        return userService.del(id);
    }

}
